﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;

namespace JasRibbonApplicatie.UserControls
{
    /// <summary>
    /// Interaction logic for Attachment.xaml
    /// </summary>
    public partial class Attachment : UserControl
    {
        public static DependencyProperty fileProperty;
        public static RoutedEvent removeClickEvent;

        public FileInfo File
        {
            get
            {
                return (FileInfo)base.GetValue(fileProperty);
            }
            set
            {
                filenameLabel.Content = value.Name;
                base.SetValue(fileProperty, value);
            }
        }
        static Attachment()
        {
            fileProperty = DependencyProperty.Register("File", typeof(FileInfo), typeof(Attachment));
            removeClickEvent = EventManager.RegisterRoutedEvent("removeClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Attachment));
        }
        public Attachment()
        {
            InitializeComponent();
        }

        public event RoutedEventHandler removeClick
        {
            add { AddHandler(removeClickEvent, value); }
            remove { RemoveHandler(removeClickEvent, value); }
        }

        private void filenameLabel_MouseUp(object sender, MouseButtonEventArgs e)
        {
            try
            {
                System.Diagnostics.Process.Start(File.FullName);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error opening file: " + File.FullName);
                Console.WriteLine("Attachment.cs filenameLabel_MouseUp exeption:" + ex.ToString());
            }  
        }
        private void removeButton_Click(object sender, RoutedEventArgs e)
        {
            e.RoutedEvent = removeClickEvent;
            RaiseEvent(e);
        }
    }
}
